package com.leyou.order.config;

import com.github.wxpay.sdk.WXPay;
//import com.github.wxpay.sdk.WXPayConfigImpl;
import com.github.wxpay.sdk.WXPayConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PayConfiguration {

    @Bean
//    @ConfigurationProperties(prefix = "ly.pay.wx")
    public WXPayConfig payConfig(){
        String appID = "wxd2bf2dba2e86a8c7";
        String mchID = "1502570431";
        String appSecret = "cec1a9185ad435abe1bced4b93f7ef2e";
        String key = "95fe355daca50f1ae82f0865c2ce87c8";
        WXConfigParam wxConfigParam = new WXConfigParam();
        wxConfigParam.setKey(key);
        wxConfigParam.setAppSecret(appSecret);
        wxConfigParam.setAppId(appID);
        wxConfigParam.setMchId(mchID);
        WXSDKConfig config = new WXSDKConfig(wxConfigParam);
        return config;
    }

    /**
     * 注册WXPay对象
     * @param payConfig 支付相关配置
     * @return WXPay对象
     * @throws Exception 连结WX失败时用到
     */
    @Bean
    public WXPay wxPay(WXPayConfig payConfig) throws Exception {
        return new WXPay(payConfig);
    }
}